package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-01
 * Time: 23:57
 */
public class FindOperation implements Ioperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("查阅图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您要查阅的书名：");
        String name = scanner.nextLine();
        //书架上有效的书本的个数：
        int currentSize = bookList.getUsedSize();
        //在这查找：
        for (int i = 0; i < currentSize; i++) {
            /**1.发生向上转型
             * 2.相当于把书架上对应的书本赋值给book
             * 3.getBooks(i);相当于书架的索引
             */
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)) {
                System.out.println("找到了这本书：");
                //展示图书：
                System.out.println(book);//直接调用了toString方法
                return;
            }
        }
        //走到这 就说明 没有这本书
        System.out.println("没有您要找的这本书！");
    }
}
